import { Http } from "@/utils/request";
import { Toast } from "@/utils/toast";
import { delayTask } from "@/utils/timer";

const baseUrl = "/guider_didi";
// 文章类型 1名导专访 2导游故事 3用户故事 4导游代言

export const get_famous_guiderlist = (
  data: { type: 1 | 2 | 3 | 4 } & MiniApp.PagingQuery,
  showError = true
) => {
  return Http.get<MiniApp.PagingData>(`${baseUrl}/article/index`, data).catch(
    (error: Error) => {
      showError && delayTask(60, () => Toast.show(error.message));
      return Promise.reject(error);
    }
  );
};
export const get_famous_detail = (id: number, showError = true) => {
  return Http.get<any>(`${baseUrl}/article/info`, { id }).catch(
    (error: Error) => {
      showError && delayTask(60, () => Toast.show(error.message));
      return Promise.reject(error);
    }
  );
};
//笔记点赞
export const common_like = (data:{
  id:number;
  type:number
}, showError = true) => {
  return Http.post<any>(`${baseUrl}/common/like`,data).catch(
    (error: Error) => {
      showError && delayTask(60, () => Toast.show(error.message));
      return Promise.reject(error);
    }
  );
};
//评论点赞
export const user_comment_like = (data:{
  id:number;
}, showError = true) => {
  return Http.post<any>(`/comment/like`,data).catch(
    (error: Error) => {
      showError && delayTask(60, () => Toast.show(error.message));
      return Promise.reject(error);
    }
  );
};
export const my_data = (data:string, showError = true) => {
  return Http.post<any>(`${baseUrl}/my/data`,{includes:data}).catch(
    (error: Error) => {
      showError && delayTask(60, () => Toast.show(error.message));
      return Promise.reject(error);
    }
  );
};

//笔记收藏
export const add_cancel_favorite1 = (data:{
  favId:number;
  type:number
  status:1|2
}, showError = true) => {
  return Http.post<any>(`/favorite/add_cancel_favorite`,data).catch(
    (error: Error) => {
      showError && delayTask(60, () => Toast.show(error.message));
      return Promise.reject(error);
    }
  );
}
export const add_cancel_favorite = (data:{
  favId:number;
  type:number
  status:1|2
}, showError = true) => {
  return Http.post<any>(`/favorite/add_cancel_favorite`,data).catch(
    (error: Error) => {
      showError && delayTask(60, () => Toast.show(error.message));
      return Promise.reject(error);
    }
  );
};
export const user_follow = (data:{
  follow_id:number;
  type:number
}, showError = true) => {
  return Http.post<any>(`${baseUrl}/user/follow`,data).catch(
    (error: Error) => {
      showError && delayTask(60, () => Toast.show(error.message));
      return Promise.reject(error);
    }
  );
};

const baseUrl2 = "/comment";
export const comment_list = (
  data: {
    relation_id: number;
    type: number;
    choose_type: 0 | 1 | 2;
    sort: string;
  },
  showError = true
) => {
  return Http.get<any>(`${baseUrl2}/list`, data).catch((error: Error) => {
    showError && delayTask(60, () => Toast.show(error.message));
    return Promise.reject(error);
  });
};
export const comment_add = (
  data: {
    relation_id: number;
    type: number;
    content: string;
    comment_id: string|number;
    score?: string;
    file_resource?: string[];
  },
  showError = true
) => {
  return Http.post<any>(`${baseUrl2}/add`, data).catch((error: Error) => {
    showError && delayTask(60, () => Toast.show(error.message));
    return Promise.reject(error);
  });
};
